<template>
  <div class="blog-markdown-viewer">
    <div v-html="getHtmlData" class="markdown-body"></div>
  </div>
</template>

<script lang="ts" setup>
  import { computed } from 'vue';
  import showdown from 'showdown';

  const converter = new showdown.Converter();
  converter.setOption('tables', true);
  converter.setOption('emoji', true);

  const props = defineProps({
    value: { type: String },
  });
  const getHtmlData = computed(() => converter.makeHtml(props.value || ''));
</script>

<style scoped lang="scss">
  .blog-markdown-viewer {
    width: 100%;
    background: transparent;
    animation: fadeIn 0.8s;
  }
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(30px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
  .markdown-body {
    color: #f6f8fa;
    font-size: 1.024rem;
    line-height: 2.05;
    font-family: 'Inter', 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
    letter-spacing: 0.01em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
  }
  .markdown-body :deep(h1),
  .markdown-body :deep(h2),
  .markdown-body :deep(h3) {
    background: linear-gradient(90deg, #40a9ff 0%, #52c41a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 900;
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  }
  .markdown-body :deep(h1) {
    font-size: 2rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.18);
    padding-bottom: 0.5rem;
  }
  .markdown-body :deep(h2) {
    font-size: 1.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 0.3rem;
  }
  .markdown-body :deep(p) {
    margin-bottom: 1rem;
  }
  .markdown-body :deep(code) {
    background: rgba(24, 144, 255, 0.28);
    color: #fff;
    border-radius: 6px;
    padding: 0.22em 0.5em;
    font-size: 1em;
    font-family: 'Fira Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  }
  .markdown-body :deep(pre) {
    background: linear-gradient(120deg, #23243a 60%, #1a1b2b 100%);
    color: #fff;
    border-radius: 10px;
    border: 1.5px solid rgba(64, 169, 255, 0.13);
    box-shadow: 0 4px 32px rgba(24, 144, 255, 0.08);
    padding: 1.2rem;
    margin: 1.2rem 0;
    position: relative;
  }
  .markdown-body :deep(pre code) {
    background: none;
    color: #fff;
    padding: 0;
  }
  .markdown-body :deep(blockquote) {
    border-left: 5px solid #40a9ff;
    background: rgba(64, 169, 255, 0.08);
    color: #b9b9b9;
    padding: 1.1rem 1.5rem;
    margin: 1.2rem 0;
    border-radius: 0 12px 12px 0;
    font-style: italic;
  }
  .markdown-body :deep(ul),
  .markdown-body :deep(ol) {
    padding-left: 1.5rem;
    margin: 1rem 0;
  }
  .markdown-body :deep(li) {
    margin-bottom: 0.5rem;
  }
  .markdown-body :deep(table) {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    overflow: hidden;
  }
  .markdown-body :deep(th),
  .markdown-body :deep(td) {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.9rem;
  }
  .markdown-body :deep(th) {
    background: rgba(24, 144, 255, 0.18);
    font-weight: 700;
  }
  .markdown-body :deep(a) {
    color: #40a9ff;
    text-shadow: 0 2px 8px rgba(64, 169, 255, 0.18);
    transition:
      color 0.2s,
      text-shadow 0.2s;
  }
  .markdown-body :deep(a:hover) {
    color: #52c41a;
    text-shadow: 0 2px 16px #52c41a;
  }
</style>
